#include "ChatGrpcClient.h"
#include "ConfigMgr.h"
#include <sstream>

ChatGrpcClient::ChatGrpcClient()
{
    //从ConfigMgr中获取chatserver的信息
    auto &cfg = ConfigMgr::GetInstance();
    std::string server_list = cfg["chatservers"]["Name"];

    std::stringstream ss(server_list);
    std::string server;

    std::vector<std::string> servers;
    while(std::getline(ss,server,','))
    {
        servers.push_back(server);
    }
    //遍历每个servers，为每个server创建连接池
    for(const auto &serverName: servers)
    {

        if(cfg[serverName]["Name"].empty()) continue;
        
        std::string host = cfg[serverName]["Host"];
        std::string port = cfg[serverName]["Port"];
        
        
        //将连接池 加入到map中
        _pools[serverName] = std::make_unique<ChatConPool>(5,host,port);
    }

}
ChatGrpcClient::~ChatGrpcClient()
{

}

AddFriendRsp ChatGrpcClient::NotifyAddFriend(std::string server_ip, const AddFriendReq &req)
{
    AddFriendRsp rsp;
    return rsp;
}


